package com.stu.collection;

import java.util.*;

public class Main {
  public static void main(String[] args) {
    // String[] array = {"hehe","aaa","Bob","Dog"};
    // for(String str : array) System.out.println(str);
    
    // Set<Integer> set = new LinkedHashSet<>(Arrays.asList(1,2,3,4));
    // for (int i : set) System.out.println(i);
    

    // // test(set);
    // // test(array);
    Integer[] ints = {1,2,3,6,5};
    Queue<Integer> queue = new PriorityQueue<>();
    // Collections.addAll(queue, 1,2,3,6,5);
    Collections.addAll(queue, ints);
    System.out.println(queue);
    // System.out.println(queue.peek());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    // System.out.println(queue.poll());
    System.out.println(queue);
  }
  public static void test(Iterable<String> ite){}

  public static void test0() {
    List<Integer> list = new ArrayList<>();
    Collections.addAll(list, 1,2,3,4);
    Set<Integer> set = new HashSet<>();
    Collections.addAll(set, 1,2,3,4);
    traverse(list.iterator());
    traverse(set.iterator());
  }
  // 遍历集合
  public static void traverse(Iterator<Integer> it) {
    while(it.hasNext()) {
      System.out.println(it.next());
    }
  }

  public static void test1() {
    // List<String> set = new ArrayList<>();
    Set<String> set = new HashSet<>();
    set.add("aaa");
    set.add("bbb");
    set.add("ccc");
    set.add("ddd");
    set.add("eee");
    set.add("fff");
    set.add("ggg");
    set.add("hhh");
    set.add("iii");
    set.add("jjj");
    set.add("kkk");
    for (int i = 0; i < 100; i++) {
      System.out.println(set);
    }
  }

  // 用一组元素初始化集合的两种方式：
  public static void test2() {
    String[] array = {"aaa","hello","Bob"};
    
    // 方式1：
    List<String> list1 = new ArrayList<>();
    Collections.addAll(list1, array);
    // 方式2：
    List<String> list2 = new ArrayList<>(Arrays.asList(array));
    // 方式1 更快，更常用。
    System.out.println(list1);
    System.out.println(list2);
  }

  // 测试 Arrays.asList() 的不可变性
  public static void test3() {
    List<Integer> list = Arrays.asList(1,2,3,4,5);
    // list.add(1);
    list.remove(2);
  }

  public static void test4() {
    Map<String,String> map = new HashMap<>();
    System.out.println(map.put("黑龙江省", "哈尔滨市"));
    map.put("吉林省", "长春市");
    System.out.println(map.put("黑龙江省", "哈"));

    System.out.println(map);
    // map.replace(key, value)

    System.out.println(map);
  }
}

